package com.ruoyi.cp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.cp.domain.VipLog;
import com.ruoyi.cp.mapper.VipLogMapper;
import com.ruoyi.cp.service.IVipLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * vip开通log 服务层实现
 *
 * @author wh
 * @date 2019-06-25
 */
@Slf4j
@Service
public class VipLogServiceImpl extends ServiceImpl<VipLogMapper, VipLog> implements IVipLogService {

    @Override
    public List<VipLog> list(VipLog vipLog) {
        LambdaQueryWrapper<VipLog> wrapper = new LambdaQueryWrapper<>();
        if (vipLog != null) {
            if (StringUtils.isNotEmpty(vipLog.getId())) {
                wrapper.eq(VipLog::getId, vipLog.getId());
            }
            if (StringUtils.isNotEmpty(vipLog.getLotteryId())) {
                wrapper.eq(VipLog::getLotteryId, vipLog.getLotteryId());
            }

            Map<String, Object> params = vipLog.getParams();
            Object openTimeBegin = params.get("openTimeBegin");
            Object openTimeEnd = params.get("openTimeEnd");
            if (StringUtils.isNotEmpty(openTimeBegin)) {
                wrapper.ge(VipLog::getOpenTime, openTimeBegin);
            }
            if (StringUtils.isNotEmpty(openTimeEnd)) {
                wrapper.le(VipLog::getOpenTime, openTimeEnd);
            }

            Object expireTimeBegin = params.get("expireTimeBegin");
            Object expireTimeEnd = params.get("expireTimeEnd");
            if (StringUtils.isNotEmpty(expireTimeBegin)) {
                wrapper.ge(VipLog::getExpireTime, expireTimeBegin);
            }
            if (StringUtils.isNotEmpty(expireTimeEnd)) {
                wrapper.le(VipLog::getExpireTime, expireTimeEnd);
            }
        }
        return baseMapper.selectList(wrapper);
    }
}
